package com.woniuxy.rabc.service.impl;

import com.woniuxy.rabc.dto.DeptDto;
import com.woniuxy.rabc.entity.SysDept;
import com.woniuxy.rabc.entity.SysUser;
import com.woniuxy.rabc.mapper.SysDeptMapper;
import com.woniuxy.rabc.mapper.SysUserMapper;
import com.woniuxy.rabc.service.DeptService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Resource
    private SysDeptMapper sysDeptMapper;
    @Resource
    private SysUserMapper sysUserMapper;
    public int deleteByPrimaryKey(Long id) {
        List<SysUser> sysUsers = sysUserMapper.selectByDeptId(id);
        if(sysUsers.size()>0){
            return 0;
        }else{
            return sysDeptMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public int insert(SysDept record) {
        return sysDeptMapper.insert(record);
    }

    @Override
    public int insertSelective(SysDept record) {
        return sysDeptMapper.insertSelective(record);
    }

    @Override
    public SysDept selectByPrimaryKey(Long id) {
        return sysDeptMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SysDept record) {
        return sysDeptMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SysDept record) {
        return sysDeptMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<SysDept> selAll(DeptDto deptDto) {
        return sysDeptMapper.selAll(deptDto);
    }

}
